// package-activity/pages/store-activity-stats-consignment/index.js
import { TARGET_TYPE } from '../../../constants/common';
import { ManageTargetInfoUpdateMixins, ManageTargetExchangeMixins, ShareSpokesmanMixins } from '../../../behaviors/page';
import { showLoading, hideLoading } from '../../../common/env';
import { getEndorsement, statsConsignmentActivity } from '../../../api/sto';
let storeId, activityId;

Page({
    mixins: [ManageTargetInfoUpdateMixins, ManageTargetExchangeMixins, ShareSpokesmanMixins],
    data: {
        statsInfo: {},
        shareInfo: {},
        endorsementInfo: {},
    },
    async onLoad(options) {
        storeId = options.storeId;
        activityId = options.activityId;
        showLoading('加载中...');
        await this._handleExchange(TARGET_TYPE.store, storeId);
        await this._handleGetDetail();
        await this._handleGetEndorsement();
        hideLoading();
    },
    async _handleGetDetail() {
        const statsInfo = await statsConsignmentActivity({ activityId });
        this.setData({ statsInfo });
        console.log('statsConsignment => 活动帮卖信息为', statsInfo);
    },
    async _handleGetEndorsement() {
        const endorsementInfo = await getEndorsement();
        const { name, storeId, homepageBg } = this.data.manageTargetInfo;
        const shareInfo = {
            name,
            storeId,
            homepageBg,
            title: endorsementInfo.spokesmanTitle,
        };
        this.setData({
            shareInfo,
            endorsementInfo,
        });
    }
})
